/*
 * Copyright (c) 2010 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.api.data.calendar.v2;

import com.google.api.client.googleapis.GoogleUrl;

/**
 * URL for calendar API.<br>
 * It contains a list of all the URL parameters for the feed.
 * 
 * @author Alain Vongsouvanh
 */
public class UrlFactory extends GoogleUrl {

  /** Root URL. */
  public static final String ROOT_URL = "https://www.google.com/calendar/feeds/";

  /** To access default account feeds and entries. */
  public static final String DEFAULT_ACCOUNT = "default";

  /**
   * Constructs a new ContactsUrl with the given URL.
   * 
   * @param url
   */
  private UrlFactory(String url) {
    super(url);
  }

  /**
   * Returns the settings URL for the given user.
   * 
   * @param email The email of the account for which to access the settings in
   *          the form "domain.com"
   * @return The URL to the Settings Feed
   */
  public static CalendarUrl getSettingsFeedUrl(String email) {
    return new CalendarUrl(ROOT_URL + email + "/settings");
  }

  /**
   * Returns the settings URL for the authenticated account.
   * 
   * @param email The email of the account for which to access the settings in
   *          the form "domain.com"
   * @return The URL to the Settings Feed
   */
  public static CalendarUrl getSettingsFeedUrl() {
    return getSettingsFeedUrl(DEFAULT_ACCOUNT);
  }

  /**
   * Returns the All Calendars URL for the authenticated account.
   * 
   * @return The URL to the All Calendars feed of the currently authenticated
   *         account
   */
  public static CalendarUrl getAllCalendarsFeedUrl() {
    return new CalendarUrl(ROOT_URL + DEFAULT_ACCOUNT + "/allcalendars/full");
  }

  /**
   * Returns the Own Calendars URL for the authenticated account.
   * 
   * @return The URL to the Own Calendars feed of the currently authenticated
   *         account
   */
  public static CalendarUrl getOwnCalendarsFeedUrl() {
    return new CalendarUrl(ROOT_URL + DEFAULT_ACCOUNT + "/owncalendars/full");
  }

  /**
   * Returns the Events Feed URL for the given calendar.
   * 
   * @param id The id of the calendar for which to access the events
   * @return The URL to the Events Feed
   */
  public static CalendarUrl getEventsFeedUrl(String id) {
    return getEventsFeedUrl(id, "private", "full");
  }

  /**
   * Returns the Events Feed URL for the given calendar with the given
   * visibility and projection.
   * 
   * @param id The id of the calendar for which to access the events
   * @param visibility The visibility with which to access the events
   * @param projection The projection with which to access the events
   * @return The URL to the Events Feed
   */
  public static CalendarUrl getEventsFeedUrl(String id, String visibility, String projection) {
    return new CalendarUrl(ROOT_URL + id + "/" + visibility + "/" + projection);
  }

  /**
   * Returns the FreeBusy Feed Url for the given user.
   * 
   * @param userId The user for which to access the FreeBusy feed
   * @return The URL to the FreeBusy Feed
   */
  public static CalendarUrl getUserFreeBusyFeedUrl(String userId) {
    return getUserFreeBusyFeedUrl(userId, "busy-times");
  }

  /**
   * Returns the FreeBusy Feed Url for the given user and projection.
   * 
   * @param userId The user for which to access the FreeBusy feed
   * @param projection The projection for which to access the FreeBusy feed. The
   *          only supported value is "busy-times"
   * @return The URL to the FreeBusy Feed
   */
  public static CalendarUrl getUserFreeBusyFeedUrl(String userId, String projection) {
    return new CalendarUrl(ROOT_URL + DEFAULT_ACCOUNT + "/freebusy/" + projection + "/" + userId);
  }

  /**
   * Returns the FreeBusy Feed Url for the given group.
   * 
   * @param userId The group for which to access the FreeBusy feed
   * @return The URL to the FreeBusy Feed
   */
  public static CalendarUrl getGroupFreeBusyFeedUrl(String groupId) {
    return getGroupFreeBusyFeedUrl(groupId, "busy-times");
  }

  /**
   * Returns the FreeBusy Feed Url for the given group and projection.
   * 
   * @param userId The group for which to access the FreeBusy feed
   * @param projection The projection for which to access the FreeBusy feed. The
   *          only supported value is "busy-times"
   * @return The URL to the FreeBusy Feed
   */
  public static CalendarUrl getGroupFreeBusyFeedUrl(String groupId, String projection) {
    return new CalendarUrl(ROOT_URL + DEFAULT_ACCOUNT + "/freebusy/group/" + groupId + "/"
        + projection);
  }

  /**
   * Returns the FreeBusy batch feed URL for the authenticated account.
   * 
   * @return The URL to the FreeBusy batch feed of the currently authenticated
   *         account
   */
  public static CalendarUrl getFreeBusyBatchFeedUrl() {
    return new CalendarUrl(ROOT_URL + DEFAULT_ACCOUNT + "/freebusy/busy-times/batch");
  }
}
